import React, { Component } from 'react';
import { Table, Button, DatePicker, message, Radio } from 'antd';
import Form from './components/SearchForm';
import Link from 'umi/link';
import moment from 'moment';
import styled from './styled.less';
import { } from './enum';
import { checkInit } from '@/utils/util';
import { connect } from 'dva';

@connect(({ analyse_maintenance }) => ({
  cond: analyse_maintenance.cond,
  list: analyse_maintenance.list || {},
}))
export default class PoliceStatistics extends Component<any> {

  state = {
    current: 1,
  };

  initCurrent = () => {
    this.setState({
      current: 1
    })
  };

  queryData(params) {

  }

  componentDidMount() {
    checkInit();
  }

  onShowSizeChange = (current, pageSize) => {
    const { dispatch, cond } = this.props;
    cond.pageSize = pageSize;
    this.setState({ current: 1 }, () => {
      dispatch({
        type: 'fireroom/updateCond',
        payload: cond
      })
    })
  }

  render() {
    const { list, buttons } = this.props;
    const { dataCnt } = list;
    const data = [{
      id: '1',
      time: '2019-10-01 12:00',
      name: 'xxx',
    }]
    const btnList = {};
    if (Array.isArray(buttons)) {
      buttons.forEach(item => {
        btnList[item.name] = item.name
      });
    }

    const ans = data && Array.isArray(data) ? data.map((item, index) => ({
      key: index,
      id: item.id,
      time: item.time,
      name: item.name,
    })
    ) : [];
    const pagination = {
      total: dataCnt,
      showTotal: total => `共 ${total} 条`,
      showSizeChanger: true,
      current: this.state.current,
      pageSizeOptions: ['10', '20', '50', '100'],
      onShowSizeChange: this.onShowSizeChange,
      onChange: (current) => {
        this.setState({
          current,
          isChangePage: true
        }, () => this.queryData({
          pageNum: current
        }));
      },
    };
    const columns = [
      {
        title: '检查时间',
        dataIndex: 'time',
      }, {
        title: '检查人',
        dataIndex: 'name',
      }, {
        title: '操作', key: 'x', render: (record, text, index) => {
          return (
            <div style={{ display: 'flex' }}>
              <Link to={`/data/analyse_maintenance/${record.id}/details`}>详情</Link>
            </div>
          )
        }
      }];
    return (
      <div>
        <Form current={this.state.current} initCurrent={this.initCurrent} new={!!btnList['新增']} />
        <Table
          columns={columns}
          pagination={pagination}
          dataSource={ans}
          loading={this.props.loading}
          bordered
        />
      </div>
    );
  }

}
